package com.campus.delivery.controller;

import com.campus.common.bean.common.Pagination;
import com.campus.common.bean.common.Resp;
import com.campus.delivery.bean.earnings.EarningsQueryParam;
import com.campus.delivery.service.DeliveryDailyEarningsService;
import com.campus.delivery.vo.earnings.EarningsRecordVo;
import com.campus.delivery.vo.earnings.EarningsStatisticsVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * <p>
 * 配送员每日收益汇总表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-06-13
 */
@RestController
@RequestMapping("/deliveryEarnings")
@Api(tags = "配送员收益统计")
public class DeliveryDailyEarningsController {

    @Autowired
    private DeliveryDailyEarningsService deliveryDailyEarningsService;

    @GetMapping("/yesterday/{deliveryId}")
    @ApiOperation("获取配送员昨日收益")
    public Resp<BigDecimal> getYesterdayEarnings(
            @ApiParam("配送员ID") @PathVariable Long deliveryId) {
        BigDecimal yesterdayEarnings = deliveryDailyEarningsService.getYesterdayEarnings(deliveryId);
        return Resp.success(yesterdayEarnings);
    }

    @GetMapping("/total/{deliveryId}")
    @ApiOperation("获取配送员累计收益")
    public Resp<BigDecimal> getTotalEarnings(
            @ApiParam("配送员ID") @PathVariable Long deliveryId) {
        BigDecimal totalEarnings = deliveryDailyEarningsService.getTotalEarnings(deliveryId);
        return Resp.success(totalEarnings);
    }

    @GetMapping("/statistics/{deliveryId}")
    @ApiOperation("获取配送员收益统计")
    public Resp<EarningsStatisticsVo> getEarningsStatistics(
            @ApiParam("配送员ID") @PathVariable Long deliveryId) {
        EarningsStatisticsVo statistics = deliveryDailyEarningsService.getEarningsStatisticsVo(deliveryId);
        return Resp.success(statistics);
    }

    @GetMapping("/records")
    @ApiOperation("获取配送员收益记录")
    public Resp<Pagination<EarningsRecordVo>> getEarningsRecords(@Validated EarningsQueryParam param) {
        PageInfo<EarningsRecordVo> pageInfo = deliveryDailyEarningsService.getEarningsRecords(param);
        return Resp.successPageable(pageInfo);
    }
}
